﻿namespace Agile.Service.Admin.WebApi.Controllers;

/// <summary>
/// 系统用户服务接口
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class SysUserController : AgileControllerBase
{
    /// <summary> 添加用户 </summary> 
    [HttpPost]
    public async Task<ResponseResult<bool>> Insert(InsertSysUserRequest request)
    => Result(await this.GetService<ISysUserService>().InsertAsync(request));

    /// <summary> 修改用户 </summary> 
    [HttpPost]
    public async Task<ResponseResult<bool>> Update(UpdateSysUserRequest request)
    => Result(await this.GetService<ISysUserService>().UpdateAsync(request));

    /// <summary> 删除用户 </summary> 
    [HttpGet]
    public async Task<ResponseResult<bool>> Remove(long userID)
    => Result(await this.GetService<ISysUserService>().RemoveAsync(userID));

    /// <summary> 是否存在用户名 </summary> 
    [HttpGet]
    public async Task<ResponseResult<bool>> IsExistUserName(string userName)
    => Result(await this.GetService<ISysUserService>().IsExistUserNameAsync(userName));

    /// <summary> 修改密码 </summary> 
    [HttpPost]
    public async Task<ResponseResult<bool>> UpdatePassword(UpdatePasswordRequest request)
    => Result(await this.GetService<ISysUserService>().UpdatePasswordAsync(request));

    /// <summary> 查询用户 </summary> 
    [HttpPost]
    public async Task<ResponseResult<PageModel<QueryPageSysUserResponse>>> QueryPage(QueryPageSysUserRequest request)
    => Result(await this.GetService<ISysUserService>().QueryPageAsync(request));

    /// <summary> 获取用户明细 </summary> 
    [HttpGet]
    public async Task<ResponseResult<GetUserResponse>> Get(long userID)
    => Result(await this.GetService<ISysUserService>().GetAsync(userID));

    /// <summary> 获取当前登录用户信息 </summary> 
    [HttpGet]
    public async Task<ResponseResult<GetUserInfoResponse>> GetUserInfo()
    => Result(await this.GetService<ISysUserService>().GetUserInfoAsync());

    /// <summary> 获取当前登录用户权限 </summary> 
    [HttpGet]
    public async Task<ResponseResult<List<string>>> GetPermCode()
    => Result(await this.GetService<ISysMenuService>().GetPermCodeAsync());
}
